From 487878216c8fcebfe82b273eb783b2dcfea3f1a6 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 5 May 2005 16:32:55 +0000 Subject: [PATCH] Add YYYYMMDD_TIME GEOCACHE_LAST_FOUND GEOCACHE_HINT GEOCACHE_PLACER to the CSV handlers. --- gpsbabel/csv_util.c | 58 +++++++++++++++++++++++++++++++++++++ gpsbabel/internal_styles.c | 2 ++ gpsbabel/style/README.style | 26 +++++++++++++++++ gpsbabel/style/tabsep.style | 2 ++ 4 files changed, 88 insertions(+) diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index 02cb3ebf8..e2423a5b1 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -2,6 +2,7 @@ Utilities for parsing Character Separated Value files (CSV) Copyright (C) 2002 Alex Mottram (geo_alexm at cox-internet.com) + Copyright (C) 2002-2005 Robert Lipe This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -603,6 +604,37 @@ xcsv_epilogue_add(char *epilogue) xcsv_file.epilogue_lines++; } +static +time_t +yyyymmdd_to_time(const char *s) +{ + int t = atol(s); + struct tm tm; + + memset(&tm, 0, sizeof(tm)); + + tm.tm_mday = t % 100; + t = t / 100; + tm.tm_mon = t % 100 - 1; + t = t / 100; + tm.tm_year = t - 1900; + return mktime(&tm); +} + +static +long +time_to_yyyymmdd(time_t t) +{ + long b; + struct tm *tm = gmtime(&t); + + b = (1900 + tm->tm_year) * 10000 + + (1 + tm->tm_mon) * 100 + + tm->tm_mday; + + return b; +} + /*****************************************************************************/ /* xcsv_parse_val() - parse incoming data into the waypt structure. */ /* usage: xcsv_parse_val("-123.34", *waypt, *field_map) */ @@ -713,6 +745,12 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp) /* Time as time_t */ wpt->creation_time = atol(s); } else + if (strcmp(fmp->key, "YYYYMMDD_TIME") == 0) { + wpt->creation_time = yyyymmdd_to_time(s); + } else + if (strcmp(fmp->key, "GEOCACHE_LAST_FOUND") == 0) { + wpt->gc_data.last_found = yyyymmdd_to_time(s); + } else /* GEOCACHING STUFF ***************************************************/ if (strcmp(fmp->key, "GEOCACHE_DIFF") == 0) { @@ -730,6 +768,14 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp) if (strcmp(fmp->key, "GEOCACHE_CONTAINER") == 0) { wpt->gc_data.container = gs_mkcont(s); } else + if (strcmp(fmp->key, "GEOCACHE_HINT") == 0) { + wpt->gc_data.hint = csv_stringtrim(s, "", 0); + } else + if (strcmp(fmp->key, "GEOCACHE_PLACER") == 0) { + wpt->gc_data.placer = csv_stringtrim(s, "", 0); + } else + + /* OTHER STUFF ***************************************************/ if ( strcmp( fmp->key, "PATH_DISTANCE_MILES") == 0) { /* Ignored on input */ } else @@ -1069,6 +1115,12 @@ xcsv_waypt_pr(const waypoint *wpt) /* time as a time_t variable */ sprintf(buff, fmp->printfc, wpt->creation_time); } else + if (strcmp(fmp->key, "YYYYMMDD_TIME") == 0) { + sprintf(buff, fmp->printfc, time_to_yyyymmdd(wpt->creation_time)); + } else + if (strcmp(fmp->key, "GEOCACHE_LAST_FOUND") == 0) { + sprintf(buff, fmp->printfc, time_to_yyyymmdd(wpt->gc_data.last_found)); + } else /* GEOCACHE STUFF **************************************************/ if (strcmp(fmp->key, "GEOCACHE_DIFF") == 0) { @@ -1086,6 +1138,12 @@ xcsv_waypt_pr(const waypoint *wpt) if (strcmp(fmp->key, "GEOCACHE_TYPE") == 0) { /* Geocache Type */ sprintf(buff, fmp->printfc, gs_get_cachetype(wpt->gc_data.type)); + } else + if (strcmp(fmp->key, "GEOCACHE_HINT") == 0) { + sprintf(buff, fmp->printfc, NONULL(wpt->gc_data.hint)); + } else + if (strcmp(fmp->key, "GEOCACHE_PLACER") == 0) { + sprintf(buff, fmp->printfc, NONULL(wpt->gc_data.placer)); } else { /* this should probably never happen */ } diff --git a/gpsbabel/internal_styles.c b/gpsbabel/internal_styles.c index aec526d80..49efddea3 100644 --- a/gpsbabel/internal_styles.c +++ b/gpsbabel/internal_styles.c @@ -498,6 +498,8 @@ static char tabsep[] = "IFIELD GEOCACHE_TYPE,\"\",\"%s\"\n" "IFIELD PATH_DISTANCE_MILES,\"\",\"%f\"\n" "IFIELD PATH_DISTANCE_KM, \"\", \"%f\"\n" +"IFIELD GEOCACHE_PLACER,\"\",\"%s\"\n" +"IFIELD YYYYMMDD_TIME,\"\",\"%ld\"\n" ; static char xmap[] = "# gpsbabel XCSV style file\n" diff --git a/gpsbabel/style/README.style b/gpsbabel/style/README.style index 9a05d4b62..bbd30e637 100644 --- a/gpsbabel/style/README.style +++ b/gpsbabel/style/README.style @@ -342,6 +342,14 @@ The fields used by the XCSV parser are as follows: example: IFIELD TIMET_TIME,"","%ld" + o YYYYMMDD_TIME + TIMET_TIME is the waypoint's creation time, if any. It's a single + decimal field containing four digits of year, two digits of month, + and two digits of date. Internally it is a LONG INTEGER and thus + requires a LONG INTEGER printf conversion. + + example: IFIELD YYYYMMDD_TIME,"","%ld" + o GEOCACHE_DIFF GEOCACHE_DIFF is valid only for geocaches and represents a DOUBLE PRECISION FLOAT. A "three and a half star" cache would therefore be "3.5" @@ -368,6 +376,24 @@ The fields used by the XCSV parser are as follows: example: GEOCACHE_TYPE,"","%s" + o GEOCACHE_PLACER + GEOCACHE_PLACER is a string containing the name of the placer of a + geocache. + + example: GEOCACHE_PLACER,"","%s" + + o GEOCACHE_LAST_FOUND + A long integer in format YYYYMMDD containing the last time this geocache + was found. + + example: GEOCACHE_LAST_FOUND,"","%ld" + + o GEOCACHE_HINT + The hint for this geocache. No additional transformation (such as rot13) + will be performed on this string. + + example: GEOCACHE_HINT,"","%s" + o PATH_DISTANCE_MILES PATH_DISTANCE_MILES outputs the total length of the route or track from the start point to the current point, in miles. This and the altitude diff --git a/gpsbabel/style/tabsep.style b/gpsbabel/style/tabsep.style index 7176e813e..b65b77686 100644 --- a/gpsbabel/style/tabsep.style +++ b/gpsbabel/style/tabsep.style @@ -51,3 +51,5 @@ IFIELD GEOCACHE_CONTAINER,"","%s" IFIELD GEOCACHE_TYPE,"","%s" IFIELD PATH_DISTANCE_MILES,"","%f" IFIELD PATH_DISTANCE_KM, "", "%f" +IFIELD GEOCACHE_PLACER,"","%s" +IFIELD YYYYMMDD_TIME,"","%ld" -- 2.30.2